From cb2327f1589c9dd7b1603a5b8345dbd94b6feb7e Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Thu, 27 Oct 2022 17:39:51 -0600 Subject: [PATCH] fix makedoc warnings. and: die on errors with file creation, creating autogen directory, or running gpsbabel. use dirname to get directory portion of $0. previously "./xmldoc/makedoc" would fail as $dir got set to "." instead of "./xmldoc". "perl xmldoc/makedoc" would work. --- xmldoc/makedoc | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/xmldoc/makedoc b/xmldoc/makedoc index 845ea4392..7ab667b20 100755 --- a/xmldoc/makedoc +++ b/xmldoc/makedoc @@ -1,10 +1,14 @@ #!/usr/bin/perl +use warnings; + +use File::Basename; + # # makedoc.in is used to generate makedoc. Editing makedoc is a bad idea. # -@options; +my %options; sub expandrw { my $read = shift; @@ -50,7 +54,7 @@ sub expandsuboptions { $olist = $options{$f}; # If no options, don't clutter things. - if ( $olist eq "" ) { return; } + if ( not defined($olist) ) { return; } # Comma separate the human-readable variation. $olist =~ s/> , \n); print FILE "\&inc_$name2;\n"; if ( !-e "$dir/$dir2/$name.xml" ) { - open TMP, ">$dir/$dir2/$name.xml"; - print TMP "\n"; - close TMP; + open $tmp, '>', "$dir/$dir2/$name.xml" or die $!; + print $tmp "\n"; + close $tmp; } } @@ -89,10 +93,12 @@ sub includef { print FORMATS "\&inc_$name2;\n"; } -$dir = $0; -$dir =~ s:/.*$::; +$dir = dirname($0); -@agdir = `mkdir -p $dir/autogen`; +qx(mkdir -p $dir/autogen); +if ( $? != 0 ) { + die "error creating autogen directory: $?"; +} open PARTS, ">$dir/autogen/_parts.xml"; print PARTS qq(\n); print PARTS qq(\n); @@ -101,7 +107,10 @@ print PARTS qq(\n); open FORMATS, ">$dir/autogen/_formats.xml"; print FORMATS qq(\n); -@formats = `./gpsbabel -^3`; +@formats = qx(./gpsbabel -^3); +if ( $? != 0 ) { + die "error running gpsbabel: $?"; +} $going = 0; $dooptions = 0; @@ -114,6 +123,7 @@ for (@formats) { s//\>/g; @line = split "\t"; + next if ( scalar(@line) < 1 ); if ( ( $line[0] eq 'file' ) || ( $line[0] eq 'serial' ) ) { $fmt = $line[2]; @@ -124,7 +134,9 @@ for (@formats) { } $skipping = 0; } - if ( $line[0] eq 'internal' || $line[5] eq 'xcsv' ) { + if ( ( $line[0] eq 'internal' ) + || ( defined( $line[5] ) && ( $line[5] eq 'xcsv' ) ) ) + { $skipping = 1; } if ( $line[0] eq 'option' && $skipping == 0 ) { @@ -141,6 +153,7 @@ for (@formats) { s//\>/g; @line = split "\t"; + next if ( scalar(@line) < 1 ); if ( $line[0] eq 'internal' ) { if ($going) { @@ -215,7 +228,10 @@ if ($going) { open FORMATS, ">$dir/autogen/_filters.xml"; print FORMATS qq(\n); -@filters = `./gpsbabel -%1`; +@filters = qx(./gpsbabel -%1); +if ( $? != 0 ) { + die "error running gpsbabel: $?"; +} $going = 0; -- 2.30.2